<template>
  <div class="person">
    <h2>汽车信息:一辆{{ car.brand }},价值{{ car.price }}万</h2>
    <button @click="changeBrand">修改汽车的品牌</button>
    <button @click="changePrice">修改汽车的价格</button>
    <button @click="changeCar">修改汽车</button>
    <hr />
    <h2>当前求和为:{{ sum }}</h2>
    <button @click="changeSum">点我sum+1</button>
  </div>
</template>
Car

<script lang="ts" setup name="Person">
  import { ref, reactive } from "vue";

  //数据
  let car = reactive({ brand: "奔驰", price: 100 });
  let sum = ref(0);

  //方法
  function changeBrand() {
    car.brand = "迈巴赫";
  }
  function changePrice() {
    car.price += 10;
  }
  function changeCar() {
    // car = {brand: "雅马哈", price: 7 }  这样写的话就不是响应式的数据了，是一个普通对象数据了
    Object.assign(car, { brand: "雅马哈", price: 7 });
    // car.value = { brand: "雅马哈", price: 7 };   ref的话直接写就行，就是响应式的
  }
  function changeSum() {
    sum.value++;
  }
</script>

<style scoped>
  .person {
    background-color: aqua;
    box-shadow: 0 0 10px;
    border-radius: 10px;
    padding: 20px;
  }

  button {
    margin-left: 5px;
    margin-right: 5px;
  }
</style>
